package com.acc.store.contorller;

import com.acc.store.common.Result;
import com.acc.store.dto.CategoryDto;
import com.acc.store.entity.Category;
import com.acc.store.service.CategoryService;
import com.acc.store.vo.CategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/category")
@RestController
@Tag(name = "分类操作")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @GetMapping("/tree")
    @Operation(summary = "获取级联机构")
    public Result tree(){
        List<CategoryVo> voList= categoryService.tree();
        return Result.success(voList);
    }

    @PostMapping("/save")
    @Operation(summary = "保存分组")
    public Result save(@RequestBody CategoryDto categoryDto){
        categoryService.saveDto(categoryDto);
        return Result.success("yes!!!!");
    }

    @DeleteMapping("/delete/{ids}")
    @Operation(summary = "批量删除分组")
    public Result delete(@PathVariable List<Long> ids){
        categoryService.delete(ids);
        return Result.success("fine!!!!");
    }
    @GetMapping("/get/{id}")
    @Operation(summary = "分组回显")
    public Result getById(@PathVariable Long id){
        Category byId = categoryService.getById(id);
        return Result.success(byId);
    }
    @PutMapping("/update")
    @Operation(summary = "更新分组")
    public Result update(@RequestBody Category category){
        categoryService.updateById(category);
        return Result.success("修改成功");
    }
}
